package com.tanhua;

import cn.hutool.core.io.FileUtil;
import com.github.tobato.fastdfs.domain.conn.FdfsWebServer;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoTest3 {

    @Autowired
    private FastFileStorageClient client;
    @Autowired
    private FdfsWebServer webServer;

    @Test
    public void test1() throws FileNotFoundException {
        //上传视频到fastDFS中

        File file = new File("C:\\Users\\muzimoo\\Desktop\\图片\\1576134125940400.mp4");
        FileInputStream is = new FileInputStream(file);
        //参数1：要上传的资源文件流
        //参数2：资源的大小
        //参数3：资源的后缀名
        //参数4：资源的属性（null）
        StorePath storePath = client.uploadFile(is,file.length(), FileUtil.extName(file),null);
        String path = storePath.getFullPath(); //资源存放到存储服务器的磁盘地址
        System.out.println(path);

        String web_url=webServer.getWebServerUrl()+path;
        System.out.println(web_url);
    }


}
